<template>
  <el-dialog
    :title="'机构备案'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="150px">

    <el-form-item label="登记中心" prop="djzx" >
      <el-select v-model="dataForm.djzx" placeholder="登记中心" style="width:100%">
          <el-option
            v-for="item in dataForm.bankList"
            :key="item.bankid"
            :label="item.bankname"
            :value="item.bankid">
          </el-option>
      </el-select>
    </el-form-item>

   <el-form-item label="变更类型" prop="chgtype">
            <el-select v-model="dataForm.chgtype" placeholder="变更类型" style="width:100%">
          <el-option
            v-for="item in dataForm.orgChangeList"
            :key="item.value"
            :label="item.text"
            :value="item.value">
          </el-option>
      </el-select>      
    </el-form-item>

    <el-form-item label="原机构名称" prop="oriorgname"  
           v-if="this.dataForm.chgtype != '1'" >
      <el-input v-model="dataForm.oriorgname" placeholder="原机构名称,多个“|”分隔"></el-input>
    </el-form-item>
    <el-form-item label="原机构代码" prop="oriorgid" 
     v-if="this.dataForm.chgtype != '1'">
      <el-input v-model="dataForm.oriorgid" placeholder="原机构代码,多个“|”分隔"></el-input>
    </el-form-item>
    <el-form-item label="现机构名称" prop="orgname"  v-if="this.dataForm.chgtype != '4'">
      <el-input v-model="dataForm.orgname" placeholder="现机构名称"></el-input>
    </el-form-item>
    <el-form-item label="现机构代码" prop="orgid" v-if="this.dataForm.chgtype != '4'">
      <el-input v-model="dataForm.orgid" placeholder="现机构代码"></el-input>
    </el-form-item>



    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          djzx: '',
          oriorgname: '',
          oriorgid: '',
          orgname: '',
          orgid: '',
          chgtype: '',
          bankList: [],
          orgChangeList: []
        },
        dataRule: {
          djzx: [
            { required: true, message: '登记中心不能为空', trigger: 'blur' }
          ],

          chgtype: [
            { required: true, message: '变更类型不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true

        this.$http({
          url: this.$http.adornUrl(`/bdc/bdcorgchginfo/item/list`),
              method: 'get',
              params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.bankList = data.bankList
              this.dataForm.orgChangeList = data.orgChangeList
            }
        })

        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          // if (this.dataForm.seqno) {
          //   this.$http({
          //     url: this.$http.adornUrl(`/bdc/bdcorgchginfo/info/${this.dataForm.seqno}`),
          //     method: 'get',
          //     params: this.$http.adornParams()
          //   }).then(({data}) => {
          //     if (data && data.code === 0) {
          //       this.dataForm.djzx = data.bdcOrgchginfo.bdcno
          //       this.dataForm.obankid = data.bdcOrgchginfo.obankid
          //       this.dataForm.oriorgname = data.bdcOrgchginfo.oriorgname
          //       this.dataForm.oriorgid = data.bdcOrgchginfo.oriorgid
          //       this.dataForm.orgname = data.bdcOrgchginfo.orgname
          //       this.dataForm.orgid = data.bdcOrgchginfo.orgid
          //       this.dataForm.chgtype = data.bdcOrgchginfo.chgtype
          //       this.dataForm.chgtime = data.bdcOrgchginfo.chgtime
          //       this.dataForm.examstate = data.bdcOrgchginfo.examstate
          //       this.dataForm.examdesc = data.bdcOrgchginfo.examdesc
          //       this.dataForm.remark = data.bdcOrgchginfo.remark
          //     }
          //   })
          // }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcorgchginfo/send`),
              method: 'post',
              data: this.$http.adornData({
                'djzx': this.dataForm.djzx,
                'oriorgname': this.dataForm.oriorgname,
                'oriorgid': this.dataForm.oriorgid,
                'orgname': this.dataForm.orgname,
                'orgid': this.dataForm.orgid,
                'chgtype': this.dataForm.chgtype

              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
